package com.category.dao.impl.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.category.dao.CatePostDao;
import com.category.meta.CatePost;

public class CatePostDaoImpl extends SqlMapClientDaoSupport implements CatePostDao {

	public int deleteCatePostById(long id) {
		CatePost delKey = new CatePost();
		delKey.setId(id);
		int rows = this.getSqlMapClientTemplate().delete("catepost.deleteCatePostById", delKey);
		return rows;
	}

	public Long insertCatePost(CatePost catePost) {
		Object result = this.getSqlMapClientTemplate().insert("catepost.insertCatePost", catePost);
		return (Long)result;
	}

	public CatePost selectCatePostById(long id) {
		CatePost selKey = new CatePost();
		selKey.setId(id);
		return (CatePost)this.getSqlMapClientTemplate().queryForObject("catepost.selectCatePostById", selKey);
	}

	@SuppressWarnings("unchecked")
	public List<CatePost> selectCatePostsByType(int cateType, int offset,
			int limit) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("type", cateType + "");
		map.put("offset", offset + "");
		map.put("limit", limit +"");
		return this.getSqlMapClientTemplate().queryForList("catepost.selectCatePostsByType", map);
	}

	public int updateCatePostById(CatePost catePost) {
		return this.getSqlMapClientTemplate().update("catepost.updateCatePostById", catePost);
	}
}
